import React from 'react';
import {HashRouter, withRouter, Redirect, Route, Switch} from 'react-router-dom';
import {LocaleProvider} from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import 'moment/locale/zh-cn';

//layout
import Layout from '@layout/public/index.jsx';

//page
import Login from '@pages/login/index.jsx';
import Home from '@pages/home/index.jsx';
import Users from '@pages/users/index.jsx';
import Detail from '@pages/detail/index.jsx';
import Opinon from '@pages/opinon/index.jsx';


const PublicLayoutChild = (props) => {
    return (
        <Layout {...props}>
            <Switch>
                <Route path="/layout/home" component={withRouter(Home)}/>
                <Route path="/layout/user" component={withRouter(Users)}/>
                <Route path="/layout/detail" component={withRouter(Detail)}/>
                <Route path="/layout/opinon" component={withRouter(Opinon)}/>
                <Redirect from="/layout" to="/login/home"/>
            </Switch>
        </Layout>
    )
};

const pageRouter = () => {
    return (
        <LocaleProvider locale={zhCN}>
            <HashRouter>
                <Switch>
                    <Route path="/login" component={withRouter(Login)}/>
                    <Route path="/layout" render={(props) => <PublicLayoutChild {...props}/>}/>
                    <Redirect from="/" to="/login"/>
                </Switch>
            </HashRouter>
        </LocaleProvider>
    )
}

export default pageRouter;